package com.kanavi.dataAccess.config;

import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class ApiAuthContextHolder {
  private static final ThreadLocal<ApiAuthEntity> threadLocal = new ThreadLocal<>();
  private static ApiAuthEntity apiAuthEntity = new ApiAuthEntity();

  public static ApiAuthEntity getAuthEntity() {
    return threadLocal.get();
  }

  public static void setParams(Map<String, Object> params) {
    if (threadLocal.get() == null) {
      init();
    }
    getAuthEntity().setParams(params);
  }

  public static void init() {
    threadLocal.set(apiAuthEntity);
  }

  public static void clear() {
    threadLocal.remove();
  }
}
